package com.java.comprehensive.arithmetic.leecode.easy;

/**
 * @Author: Dgg
 * @Date: 2021/10/27 22:49
 */
public class LeetCode_13 {
	public static void main(String[] args) {
		Solution solution = new Solution();
		String s = "VI";
		int i = solution.romanToInt(s);
		System.out.println(i);
	}

	static class Solution {
		public int romanToInt(String s) {
			char c = s.charAt(0);
			int tempNum = getValue(c);
			int result = 0;
			for (int i = 1; i < s.length(); i++) {
				int num = getValue(s.charAt(i));
				if (tempNum < num) {
					result -= tempNum;
				} else {
					result += tempNum;
				}
				tempNum = num;
			}
			result += tempNum;
			return result;
		}

		public int getValue(char val) {
			switch (val) {
			case 'I':
				return 1;
			case 'V':
				return 5;
			case 'X':
				return 10;
			case 'L':
				return 50;
			case 'C':
				return 100;
			case 'D':
				return 500;
			case 'M':
				return 1000;
			default:
				return 0;
			}
		}
	}

}
